package Gather.StreamExercise.MethodReference.MethodExercise;

/**
 * ClassName:Student
 * Package:Gather.StreamExercise.MethodReference.MethodExercise
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/2/25-16:24
 * @Version:v1.0
 */
public class Student {
    private String name;
    private int age;

    public Student() {
    }
    public Student(String str) {
        this.name = str.split(",")[0];
        this.age = Integer.parseInt(str.split(",")[1]);

    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        if (age<18||age>40){
//            System.out.println("年龄超出范围");
            //抛出一个异常
            throw new RuntimeException();
        }else {
            this.age = age;
        }

    }

    public String toString() {
        return "Student{name = " + name + ", age = " + age + "}";
    }
}
